package com.dayuanit.dy15.atm.controller;

import com.dayuanit.dy15.atm.annotation.AutoWired;
import com.dayuanit.dy15.atm.annotation.Component;
import com.dayuanit.dy15.atm.annotation.RequestMapping;
import com.dayuanit.dy15.atm.dto.FlowDTO;
import com.dayuanit.dy15.atm.dto.ResponseDTO;
import com.dayuanit.dy15.atm.holder.PageHolder;
import com.dayuanit.dy15.atm.service.FlowService;
import com.dayuanit.dy15.atm.service.impl.FlowServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Component(value = "flowController")
public class FlowController extends BaseController {

    private FlowService flowService;

    @AutoWired("flowServiceImpl")
    public void setFlowService(FlowService flowService) {
        this.flowService = flowService;
    }

    @RequestMapping(value = "/flow/listFlow.do")
    public ResponseDTO listFlow(HttpServletRequest request, HttpServletResponse response) {
        String cardId = request.getParameter("cardId");
        String currentPage = request.getParameter("currentPage");

        PageHolder<List<FlowDTO>> pageHolder = flowService.queryFLows(Long.valueOf(cardId), Integer.parseInt(currentPage));

        return ResponseDTO.sucess(pageHolder);
    }

    @RequestMapping(value = "/card/listTop10.do")
    public ResponseDTO listTop10(HttpServletRequest request, HttpServletResponse response) {
        return ResponseDTO.sucess(flowService.top10(getUserId(request)));
    }
}
